// 192.168.31.230
const axios = require('axios');
const fs = require('fs');
const url = 'http://192.168.31.230:1224/api/ocr';

const file = fs.readFileSync('2.png');

const b64 = file.toString('base64');
axios
  .post(url, { base64: b64 })
  .then((response) => {
    let data = response.data;

    if (data.code === 100) {
      data.data.forEach((item) => {
        let box = item.box;
        console.log(
          `识别到的文本：[ ${item.text} ]  左上角坐标${box[0][0]},${box[0][1]}  右下角坐标${box[2][0]},${box[2][1]}`,
        );
      });
    } else if (data.code === 300) {
      console.log('base64解码失败');
    } else if (data.code === 101) {
      console.log('没有识别到文字');
    }
  })
  .catch((error) => {
    console.error('识别失败:', error);
  });
